package com.toubutu.audio.auth.service.impl;

import cn.hutool.core.lang.UUID;
import com.toubutu.audio.auth.service.SendVerifyCodeService;
import com.toubutu.audio.utils.MailSendUtil;
import com.toubutu.constants.RedisKey;

import com.toubutu.util.RedisService;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author 戒躁
 * @version 1.0
 * @date 2023年10月21日 2:02
 */
@Service
public class VerifyCodeImpl implements SendVerifyCodeService {
    @Resource
    private RedisService redisService;
    @Resource
    private MailSendUtil mailSendUtil;
    @Override
    public void sendEmailCode(String email) {
        Long random = RandomUtils.nextLong(100000, 999999);
        redisService.set(RedisKey.EMAIL_CODE +email,random, 60);
        mailSendUtil.sendMessage(email,random.toString());
    }

    @Override
    public String generateSubmitCode() {
        return UUID.fastUUID().toString();
    }
}
